package com.wx.controller.collectController;

import com.wx.entity.WxUserModel;
import com.wx.pojo.WxCollect;
import com.wx.service.ICollectService;
import com.wx.service.IUserProductDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/collect")
public class CollectController extends WxUserModel {

    @Autowired
    private ICollectService iCollectService;
    @Autowired
    private IUserProductDetailService iUserProductDetailService;

    @GetMapping("listCollectpage/{page}")
    public String listCollectpage(ModelMap map, @PathVariable("page") Integer page){
        map.addAttribute("listCollect",iCollectService.listCollect(new WxCollect(),page,1));
        return "listCollect1111";
    }

    /**
     * 集采活动列表
     * @param map
     * @param status 集采状态 1 进行中 2已结束
     * @return
     */
    @GetMapping("/listCollect")
    public String listCollect(ModelMap map,Integer status){
        //正在集采列表
        map.addAttribute("listCollect",iUserProductDetailService.listModelDetail(null,1,1));
        //已经结束集采列表
        map.addAttribute("listCollected",iUserProductDetailService.listModelDetail(null,2,1));
        return "collectView/listCollect";
    }

    @GetMapping("getCollectDetail")
    public String getCollectDetail(ModelMap map, @RequestParam(value = "collect_number",defaultValue = "101547722416395") String collect_number,@RequestParam(value = "user_id",defaultValue ="3" ) Integer user_id, HttpServletRequest request){
        if (getUserModel(request).getId()!=null){
            user_id=getUserModel(request).getId();
        }
        map.addAttribute("collectModel",iUserProductDetailService.getModelDetail(collect_number,user_id));
//        map.addAttribute("list",iUserProductDetailService.listModelJoinUser(collect_number));

        return "collectView/collectDetail";
    }
}
